/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package modeles.beans;

import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import modeles.Rayon;
import modeles.servicesClient.ServicesRayons;

/**
 *
 * @author Fred
 */
@ManagedBean(name = "vueAjoutRayon")
@RequestScoped
public class AjoutRayonBean implements Serializable {

    private ServicesRayons services;
    private Rayon rayon;

    /**
     * Creates a new instance of AjoutRayonBean
     */
    public AjoutRayonBean() {
        services = new ServicesRayons();
    }

    public Rayon getRayon() {
        if (rayon == null) {
            rayon = new Rayon();
        }
        return rayon;
    }

    public void ajouterRayon() {
        if (rayon != null) {
            if (services.ajouterRayon(rayon)) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Le rayon a bien été ajouté !", null));
            }
        }
    }
}
